package com.github.cyf.ppt.model;

import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.poi.xslf.usermodel.XSLFTextRun;
import java.awt.*;

/**
 * @author chenyifan
 * @create 2025-04-17 17:13
 */
@Data
@Accessors(chain = true)
public class Text {
    // 文本内容
    private String text;
    // 字体大小
    private Double fontSize;
    // 字体样式
    private String fontFamily;
    // 字体颜色
    private Color color;
    // 加粗
    private boolean isBlod;
    // 斜体
    private boolean isItalic;

    public static Text of(String text) {
        return of(text, null, null, null, false, false);
    }

    public static Text ofBlod(String text) {
        return of(text, null, null, null, true, false);
    }

    public static Text ofBlod(String text, Color color) {
        return of(text, null, null, color, true, false);
    }

    public static Text of(String text, String fontFamily, Double fontSize, Color color, boolean isBlod, boolean isItalic) {
        return new Text(text, fontFamily, fontSize, color, isBlod, isItalic);
    }

    public Text(String text, String fontFamily, Double fontSize, Color color, boolean isBlod, boolean isItalic) {
        this.text = text;
        this.fontFamily = fontFamily;
        this.fontSize = fontSize;
        this.color = color;
        this.isBlod = isBlod;
        this.isItalic = isItalic;
    }

    public void setStyleToTextRun(XSLFTextRun textRun) {
        if (fontSize != null) {
            textRun.setFontSize(fontSize);
        }
        if (fontFamily != null) {
            textRun.setFontFamily(fontFamily);
        }
        if (color != null) {
            textRun.setFontColor(color);
        }
        textRun.setBold(isBlod);
        textRun.setItalic(isItalic);
        textRun.setText(text);
    }
}
